package org.example;

import com.sun.source.tree.BinaryTree;
import org.example.BinaryTree.Binary;
import org.example.NodeList.ListNode;
import org.example.Sort.MargeSort;
import org.example.Tool.Logar;
import org.example.Tool.Tool;
import org.example.halfsearch.Half;

import java.util.*;

public class Main {
    public int minDepth(Binary root) {
        if(root==null) return 0;
        if(root.left==null&&root.right==null) return 1;
        Stack<Binary> st = new Stack();

        int count=0;
        int right = 0;
        if(root.left!=null){
            st.push(root.left);
            count++;
            while(!st.empty()){
                Binary temp = st.pop();
                boolean a = false;
                if(temp.right!=null){
                    st.push(temp.right);
                    a = true;
                    count++;

                }
                if(temp.left!=null){
                    st.push(temp.left);
                    if(!a)count++;

                }
            }
        }
        if(root.right!=null){
            right++;
            st.push(root.right);
            while(!st.empty()){
                Binary temp = st.pop();
                boolean a = false;
                if(temp.right!=null){
                    st.push(temp.right);
                    a = true;
                    right++;
                }
                if(temp.left!=null){
                    st.push(temp.left);
                    if(!a)right++;

                }
            }
        }
        int result = count>right?right==0?count:right:count==0?right:count;
        return result;
    }
    public ListNode swapPairs(ListNode head) {
        if(head!=null&&head.next==null) return head;
        List<Integer> ls = new ArrayList();
        while(head!=null){
            ls.add(head.val);
            head = head.next;
        }
        ListNode node =null;
        for(int i=ls.size()-1;i>=0;i--){
            node = new ListNode(ls.get(i-1),node);
            node = new ListNode(ls.get(i),node);
            i--;

        }

        return node;
    }
    public static void main(String[] args) {
//        System.out.println(new Main().lengthOfLongestSubstring("dvdf"));
       Object i = 5;
       Long l = (long) i;
        System.out.println(l);
    }
}
